import { createRouter, createWebHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'
import Layout from '../layout/Layout.vue'
import AdminLayout from '../layout/AdminLayout.vue'

const masterRoutes: RouteRecordRaw = {
  path: '/',
  component: Layout,
  children: [
    {
      path: '/master',
      name: 'master',
      component: () => import('../views/master/Home.vue')
    }
  ]
}

export const adminRoutes: RouteRecordRaw = {
  path: '/',
  redirect: '/index',
  component: AdminLayout,
  children: [
    {
      path: '/index',
      name: 'index',
      meta: { title: '首页', icon: 'House', affix: true },
      component: () => import('../views/admin/Home.vue')
    }
  ]
}
const routes: RouteRecordRaw[] = [masterRoutes, adminRoutes]

const router = createRouter({
  history: createWebHistory(`${import.meta.env.VITE_BASE}{{pagePath}}`),
  routes: [...routes]
})

router.beforeEach((to, from, next) => {
  document.title = to.meta.title || import.meta.env.VITE_SYS_NAME
  next()
})
export default router
